using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class SubprocessDetailMap : EntityTypeConfiguration<SubprocessDetail>
    {
        public SubprocessDetailMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Evaluation1)
                .HasMaxLength(500);

            this.Property(t => t.Evaluation2)
                .HasMaxLength(500);

            // Table & Column Mappings
            this.ToTable("SubprocessDetail");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.OrderProcessID).HasColumnName("OrderProcessID");
            this.Property(t => t.DesignDetailID).HasColumnName("DesignDetailID");
            this.Property(t => t.UnitID).HasColumnName("UnitID");
            this.Property(t => t.ResponsibleID).HasColumnName("ResponsibleID");
            this.Property(t => t.WorkplaceID).HasColumnName("WorkplaceID");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.StartDate).HasColumnName("StartDate");
            this.Property(t => t.EndDate).HasColumnName("EndDate");
            this.Property(t => t.State).HasColumnName("State");
            this.Property(t => t.ExaminerID).HasColumnName("ExaminerID");
            this.Property(t => t.Evaluation1).HasColumnName("Evaluation1");
            this.Property(t => t.Evaluation2).HasColumnName("Evaluation2");

            // Relationships
            this.HasOptional(t => t.DesignDetail)
                .WithMany(t => t.SubprocessDetails)
                .HasForeignKey(d => d.DesignDetailID);
            this.HasOptional(t => t.Employee)
                .WithMany(t => t.SubprocessDetails)
                .HasForeignKey(d => d.ExaminerID);
            this.HasOptional(t => t.Employee1)
                .WithMany(t => t.SubprocessDetails1)
                .HasForeignKey(d => d.ResponsibleID);
            this.HasOptional(t => t.OrderProcess)
                .WithMany(t => t.SubprocessDetails)
                .HasForeignKey(d => d.OrderProcessID);
            this.HasOptional(t => t.Unit)
                .WithMany(t => t.SubprocessDetails)
                .HasForeignKey(d => d.UnitID);
            this.HasOptional(t => t.Workplace)
                .WithMany(t => t.SubprocessDetails)
                .HasForeignKey(d => d.WorkplaceID);

        }
    }
}
